﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Course.Controllers;
using Course.Models;
using Course.Views;

namespace Course.Views
{
    public partial class StuHome : Form
    {
        private StuHomeController _controller;
        public StuHomeController Controller {
            get { return _controller; }
            set { 
                _controller = value;
                this.textBox1.DataBindings.Add("Text",Controller.Model,"UserName");
                this.textBox2.DataBindings.Add("Text",Controller.Model,"UserId");
                this.textBox3.DataBindings.Add("Text",Controller.Model,"Grade");
                this.textBox4.DataBindings.Add("Text",Controller.Model,"Class");
                this.textBox5.DataBindings.Add("Text",Controller.Model,"CourseId");
                this.textBox6.DataBindings.Add("Text", Controller.Model, "SearchValue");
            }
        }
        public StuHome()
        {
            InitializeComponent();
        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void StuHome_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“courseDataSet1.CourseView”中。您可以根据需要移动或删除它。
            this.courseViewTableAdapter1.Fill(this.courseDataSet1.CourseView);
            // TODO: 这行代码将数据加载到表“courseDataSet.CourseView”中。您可以根据需要移动或删除它。
            this.courseViewTableAdapter.Fill(this.courseDataSet.CourseView);

        }

        private void button4_Click(object sender, EventArgs e)
        {
       
            _controller.searchCourse();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (Controller.SaveChanges())
            {
                MessageBox.Show("更改成功");
            }
            else {
                MessageBox.Show("更改失败");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (Controller.selectCourse())
                MessageBox.Show("选课成功");
            else
                MessageBox.Show("选课失败");
        }
    }
}
